/*
 * Kinect Player
 * Kulikov Victor
 * kulikov.victor@gmail.com
 * GNU Lisence 2011
 */
#include "dubslider.h"
#include <QPainter>
DubSlider::DubSlider(QWidget *parent) :
    QSlider(parent)
{
    leftflag = -1;
    rightflag = -1;
    showflag = false;

    highcolor.setRgb(0,255,0,255);
    setOrientation(Qt::Horizontal);
}
void DubSlider::paintEvent(QPaintEvent *event)
{


     QPainter painter(this);
    if(showflag)
    {
        double width = this->width();
        int height = this->height();
        double max = this->maximum();
        double min = this->minimum();

        double scale=width/(max-min);


        QRect rect;
        rect.setTop(height/2-2);
        rect.setBottom(height/2+2);
        rect.setLeft(leftflag*scale);
        rect.setRight(rightflag*scale);
        painter.setPen(highcolor);
        painter.setBrush(highcolor);
        painter.fillRect(rect,highcolor);

        QPointF left[3] = {
            QPointF(rect.left(), rect.bottom()),
            QPointF(rect.left(), rect.bottom()+5),
            QPointF(rect.left()-5, rect.bottom())
        };
        QPointF right[3] = {
            QPointF(rect.right(), rect.bottom()),
            QPointF(rect.right(), rect.bottom()+5),
            QPointF(rect.right()+5, rect.bottom())
        };
        painter.drawPolygon(left,3);
        painter.drawPolygon(right,3);
        //painter.drawText();
    }
    QSlider::paintEvent(event);

}
void DubSlider::setLeftFlag(int f)
{
    if(-1==f)
    {
        leftflag = this->value();
    }else{
        leftflag = f;
    }
    if(leftflag>rightflag)
    {
        rightflag = leftflag;
    }
    showflag = true;
    this->update();
}
void DubSlider::cleanFlags()
{
    rightflag = leftflag = -1;
    showflag =false;
    this->update();
}

void DubSlider::setRightFlag(int f)
{
    if(-1==f)
    {
        rightflag = this->value();
    }else{
        rightflag = f;
    }
    if(leftflag>rightflag)
    {
        leftflag = rightflag;
    }
    showflag = true;
    this->update();
}

int DubSlider::leftFlag()
{
    return leftflag;
}

int DubSlider::rightFlag()
{
    return rightflag;
}
void DubSlider::setProcess(bool process)
{
    isProcess  = process;
}
void DubSlider::setHighlightColor(QColor color)
{
    highcolor = color;
}
